package com.damon.day03;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;

import java.io.IOException;
import java.util.List;

/**
 * @Date 2020/4/17 21:27
 * @Created by Damon
 */
public class HistoryQuery {
    public static void main(String[] args) throws IOException {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        /*
        * 从数据库的act_ge_bytearray表中读取两个资源文件
        * 将两个资源文件保存到路径: d:\bpmn
        * */
        RepositoryService repositoryService = processEngine.getRepositoryService();

        HistoryService historyService = processEngine.getHistoryService();

        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();

        historicActivityInstanceQuery.processInstanceId("2501");

        List<HistoricActivityInstance> list = historicActivityInstanceQuery
                .orderByHistoricActivityInstanceStartTime().asc()
                .list();

        for (HistoricActivityInstance instance: list) {
            System.out.println(instance.getActivityId());
            System.out.println(instance.getActivityName());
            System.out.println(instance.getProcessDefinitionId());
            System.out.println(instance.getProcessInstanceId());
        }

    }
}
